<template>
  <Form
    ref="pgoodsForm"
    :model="form"
    :rules="rules"
    @keydown.enter.native="handleSubmit"
    inline
    :label-width="80">
    <FormItem prop="ctime" style="width: 250px" label="创建日期：">
      <DatePicker v-model="form.ctime" type="date" placeholder="请选择创建日期"></DatePicker>
      <!-- <Input type="text" v-model="form.name" placeholder="请输入商品名称" /> -->
    </FormItem>
    <FormItem prop="time" style="width: 300px" label="活动时间：">
      <DatePicker v-model="form.time" type="daterange" format="yyyy-MM-dd" placeholder="请选择活动时间"></DatePicker>
      <!-- <Input type="text" v-model="form.name" placeholder="请输入商品名称" /> -->
    </FormItem>
    <FormItem style="float: right">
      <Button @click="handleSubmit" icon="md-search" type="primary">
        搜索
      </Button>
    </FormItem>
  </Form>
</template>
<script>
export default {
  name: 'PgoodsForm',
  props: {
    ctimeRules: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data () {
    return {
      form: {
        ctime: '',
        time: []
      }
    }
  },
  computed: {
    rules () {
      return {
        ctime: this.ctimeRules
      }
    }
  },
  methods: {
    handleSubmit () {
      this.$refs.pgoodsForm.validate((valid) => {
        if (valid) {
          this.$emit('on-success-valid', {
            ctime: this.form.ctime ? this.$moment(this.form.ctime).format('YYYY-MM-DD') : '',
            btime: (this.form.time && this.form.time[0]) ? this.$moment(this.form.time[0], this.$moment.ISO_8601).format('YYYY-MM-DD') : '',
            etime: (this.form.time && this.form.time[1]) ? this.$moment(this.form.time[1], this.$moment.ISO_8601).format('YYYY-MM-DD') : ''
          })
        }
      })
    }
  }
}
</script>
